package element.synt;

import element.ast.AstNode;
import element.base.Synt;
import element.base.TreeNode;
import intermediate_representation.LabelRP;
import table.InterCodeTable;

public class LAndExp extends Synt {

    public void Jump(String successLabel, String failureLabel, boolean need) {
        int nowindex = InterCodeTable.regindex;
        TreeNode node0 = this.getNodes().get(0);
        if (node0 instanceof EqExp) {
            ((EqExp) node0).Jump(successLabel, failureLabel, need);
        } else {
            EqExp right = (EqExp) this.getNodes().get(2);
            LAndExp left = (LAndExp) node0;
            String newLabel = InterCodeTable.pushLabel();
            left.Jump(newLabel, failureLabel, false);
            InterCodeTable.addCode(new LabelRP(newLabel));
            right.Jump(successLabel, failureLabel, need);
        }
        InterCodeTable.regindex = nowindex;
    }
}
